<template>
  <div class="GEmployeeManage">
    <filterPanel filterName="GEmployeeManageFilter" filterTitle="从业人员查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GEmployeeManageTable" :tableLoading="loading" tableTitle="从业人员列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button type="primary" @click="exportExcel">导出列表</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	import {mapGetters} from "vuex";

	export default {
		name: "GEmployeeManage",
		props: {},
		data() {
			return {
				currentPath: '/employee_list',
				filterData: [
					{
						title: '人员姓名',
						name: 'employee_name',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '联系电话',
						name: 'employee_mobile',
						type: 'input',
						value: '',
						maxlength: '11',
						isShow: true,
						isSelected: true
					},
					{
						title: '身份证号',
						name: 'card_no',
						type: 'input',
						value: '',
						maxlength: '18',
						isShow: true,
						isSelected: true
					},
					{
						title: '所属企业',
						name: 'company_name',
						type: 'input',
						value: '',
						maxlength: '20',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						name: 'company_type',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '物流', value: 0},
							{label: '快递', value: 1},
							{label: '分拣中心', value: 2},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '在职状态',
						name: 'status',
						type: 'select',
						optionList: [
							{label: '全部', value: ''},
							{label: '在职', value: '1'},
							{label: '离职', value: '2'},
						],
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '入职时间',
						name: 'registration_date',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},

				],
				form: {
					employee_name: '',
					employee_mobile: '',
					card_no: '',
					company_name: '',
					company_type: '',
					status: '',
					registration_date: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '人员姓名',
						width: 120,
						name: 'employee_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '联系电话',
						width: 180,
						name: 'employee_mobile',
						isShow: true,
						isSelected: true
					},
					{
						title: '身份证号',
						width: 180,
						name: 'card_no',
						isShow: true,
						isSelected: true
					},
					{
						title: '所属企业',
						width: 200,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '企业类型',
						width: 120,
						name: 'type_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '职位',
						width: 120,
						name: 'profession_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '入职时间',
						width: 180,
						name: 'create_time',
						isShow: true,
						isSelected: true
					},
					{
						title: '在职状态',
						width: 120,
						name: 'status_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 200,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'detail',
								name: '详情'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				download_url: ''
			};
		},
		computed: {
			postData() {
				let data = {
					employee_name: this.form.employee_name,
					employee_mobile: this.form.employee_mobile,
					card_no: this.form.card_no,
					company_name: this.form.company_name,
					company_type: this.form.company_type,
					status: this.form.status,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.registration_date && this.form.registration_date.length > 0) {
					data.start_created_time = this.form.registration_date[0] / 1000;     //开始时间
					data.end_created_time = this.form.registration_date[1] / 1000;     //结束时间
				}
				return data;
			},
			...mapGetters(['authority']),
			isLook() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].q;
			},
		},
		watch: {},
		components: {},
		methods: {
			//导出
			exportExcel() {
				this.$import_excal(this.download_url || "");
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.tableData = [];
				this.$axios.post(this.$api.admin_employeeList, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						let arr = ['物流', '快递', '分拣中心']
						this.tableData = data.list.filter(item => {
							item.type_desc = arr[item.type];
							item.status_desc = item.status == 1 ? '在职' : '离职';
							item.detail = this.isLook;
							return item;
						});
						this.download_url = data.download_url || ''
						this.total = data.pagination.total_count || 0;
					} else {
						this.total = 0
						this.tableData = [];
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				this.$toRoutePath({
					path: "/employee_list/employee_list_detail",
					edit: true,
					query: {employee_id: data.employee_id}
				});
			},
		},
		mounted() {
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/personnelManage/employeeList/index.less">

</style>
